<?php

/**
 * DISABLE
 */

include 'common.php';
$username = $_COOKIE['username'];
$token = $_COOKIE['token'];

chksymbol($username);
chksymbol($token);

//$conn = connect2db();
$result = mysql_query("select * from userinfo where username='$username' and token='$token'");
$row = mysql_fetch_array($result);

if($row)
{
	$addr = $_SERVER['REMOTE_ADDR'];
	$time = time();
	mysql_query("set msg utf8");
	$connkey = $row['connectkey'];
	$tuser = mysql_query("select * from userinfo where ukey='$connkey' limit 1");
	$tuser_data = mysql_fetch_array($tuser);
	$tusername = $tuser_data['username'];
	$result2 = mysql_query("select * from usermsg where username='$tusername' order by lasttime desc limit 1");
	$row2 = mysql_fetch_array($result2);
	safelog($username, 'DOWNLOAD_MSG', $conn);
	if($result2)
	{
		$errorcode = 1;
		$lastmsg = $row2['msg'];
		$lasttime = $row2['lasttime'];
	}
}else
{
	$errorcode = 5;	
	$lasttime = 0;
	$lastmsg = '';
}
echo json_encode(array('errorcode'=>$errorcode, 'lastmsg'=>$lastmsg, 'lasttime'=>$lasttime));
mysql_free_result($result);
mysql_close($conn);

?>